//@author A0099619J
#include "Time.h"

Time::Time() {
	*this = NULL_TIME;
}

Time::Time(int hh, int mm) {
	hour = hh;
	minute = mm;
}

Time Time::getCurrentTime() {
	time_t t = time(0);
    struct tm now;
	localtime_s(&now, &t);

	Time time(now.tm_hour, now.tm_min);
	return time;
}

std::string Time::formatTime() {
	if (*this==NULL_TIME)
		return "NIL";
	else {
		std::string string = std::to_string(hour) + ":";
		if (minute < 10) {
			string += "0";
		}
		string += std::to_string(minute);
		return string;
	}
}

bool Time::isValidTime() {
	if (0 <= hour && hour < 24 && 0 <= minute && minute < 60) {
		return true;
	}
	else {
		return false;
	}
}

int Time::getHour()
{
	return hour;
}

int Time::getMinute()
{
	return minute;
}

bool Time::operator<(const Time& other) const
{
	if (hour < other.hour)
		return true;
	if (hour == other.hour && minute < other.minute)
		return true;
	return false;
}

bool Time::operator<=(const Time& other) const
{
	if (hour <= other.hour)
		return true;
	if (hour == other.hour && minute <= other.minute)
		return true;
	return false;
}

bool Time::operator>(const Time& other) const
{
	if (hour > other.hour)
		return true;
	if (hour == other.hour && minute > other.minute)
		return true;
	return false;
}

bool Time::operator>=(const Time& other) const
{
	if (hour > other.hour)
		return true;
	if (hour == other.hour && minute >= other.minute)
		return true;
	return false;
}

bool Time::operator==(const Time& other) const
{
	return hour == other.hour && minute == other.minute;
}

bool Time::operator!=(const Time& other) const
{
	return !(*this == other);
}

std::ostream& operator<<(std::ostream& os, const Time& t)
{
	if (t.hour < 10) {
		os << '0';
	}
	os << t.hour * 100 + t.minute;
	return os;
}